package com.abcdefg.controller;

import com.abcdefg.model.ProductInfo;
import com.abcdefg.service.ProductService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("product")
public class ProductController  {
    @Autowired
    private ProductService productService;

    @RequestMapping("/{productId}")
    public ProductInfo getProductById(@PathVariable("productId") Integer productId) {
        System.out.println("收到请求,Id:" + productId);
        return productService.selectProductById(productId);
    }


    @RequestMapping("p1")
    public String p1(@RequestParam("id") Integer id, String userName, HttpServletResponse
                     response) {
        System.out.println("接收到参数userName:"+userName);
        response.setStatus(502);
        return "接收到参数id:" + id;
    }
    @RequestMapping("p2")
    public String p2(@RequestParam("id") Integer id,@RequestParam("name") String name) {
        return "接收到参数id,name:" +id+","+ name;
    }
    @RequestMapping("p3")
    public String p3( ProductInfo productInfo) {
        return "接收到参数productInfo:" + productInfo;
    }
    @RequestMapping("p4")
    public String p4(@RequestBody ProductInfo productInfo) {
        return "接收到参数productInfo:" + productInfo;
    }
}
